<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" href="../../css/swiper.min.css">
    <link rel="stylesheet" href="../../font/iconfont.css">

</head>
<body>
	<div class="aui-content aui-padded-l-15 aui-padded-r-15" style="margin-top:15px; padding-bottom:40px;" id="address">
		<div id="wudongtai_box" class="none">
			<img src="../../image/wudongtai.png" id="wudongtai_img" />
			<p id="wudongtai_txt"></p>
		</div>
		<!--
		<div class="aui-list aui-select-list aui-media-list aui-margin-b-15" style="background-image:none;">
		    <div class="aui-list-item">
	            <div class="aui-media-list-item-inner">
	                <div class="aui-list-item-inner">
	                    <div class="aui-list-item-text">
	                        <div class="aui-list-item-title">收货人：张三</div>
	                        <div class="aui-list-item-right">15225442255</div>
	                    </div>
	                    <div class="aui-list-item-title">收货地址：河南省洛阳市洛龙区开元大道学子街八号洛阳理工学院</div>
	                </div>
	            </div>
       	    </div>
       	    <div class="aui-info aui-padded-0">
            	<div class="aui-list-item border-none">
		            <div class="aui-list-item-inner">
		                <label onclick="setDefault();"><input class="aui-radio" type="radio" name="radio">
		             	   <span class="aui-margin-l-10">设为默认</span>
		                </label>
		            </div>
		        </div>
                <div class="aui-info-item aui-margin-r-15">
                	<a href="#" class="aui-margin-r-15 aui-text-success" onclick="openAdrinfo();"> <i class="aui-iconfont aui-icon-edit"></i></a>
                	<a href="#" class=" aui-text-danger" onclick="delAdr();"><i class="aui-iconfont aui-icon-trash"></i></a>
                </div>
            </div>
    	</div>
    	-->
	</div>
	<div class="hong-kuang" onclick="openAdAdr();">
		<p>新增收货地址</p>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>
var db_key = 'user',db_user,myParam,adrdata = {};
apiready = function(){
	myParam = api.pageParam;
	getuser();
	loadAdress();

	//如果从提交订单页面打开，选择收货地址，提示如何选择
	if(myParam.tishi == '1'){
		api.toast({msg:'请点击地址右上角选择！'});
	}
	//监听退出登录
    api.addEventListener({
        name: 'adadr_self'
    }, function(ret, err) {
        loadAdress();
    });
}
//获取用户储存在本地的数据
function getuser() {
    db_user = $api.getStorage(db_key);
}
//加载内容
function loadAdress() {
	api.showProgress();//显示加载进度框
	var useParam = {
    	rtk : RSapi.myrtk,
        mytoken : db_user.mytoken,
    };
	api.ajax({
		url: RSapi.base+RSapi.AdrList,
		method: 'post',
		cache: false,
		timeout: 30,
		dataType: 'json',
		data: { values: useParam },
	}, function(ret, err){
		if(err){
			//api.toast({msg: JSON.stringify(err)});
			api.toast({msg: err.msg});
//			api.alert({msg:err.msg});
		}else {
			if (ret.status==1) {
				//成功了
				$api.html($api.byId("address"), ' ');
				$api.append($api.byId("address"),ret.info);
				api.parseTapmode();
				eval('status_'+status+'=true;');
				api.hideProgress();//隐藏加载进度框
			}else if(ret.status==2){
				//没有内容
				$api.html($api.byId("address"), ' ');
				$api.removeCls($api.byId('wudongtai_box'), 'none');//显示无动态框
				$api.html($api.byId('wudongtai_txt'), ret.info);//显示提示内容
			}
		}
		api.hideProgress();
	});
}
//添加收货地址
function openAdAdr(){
	api.openWin({
        name: 'win_adadr',
        url: '../win/adrinfo_win.html',
    });
}
//编辑收货地址
function openEditAdr(id){
	NowAdrInfo(id);
	api.openWin({
        name: 'win_adadr',
        url: '../win/adrinfo_win.html',
        pageParam: {myadr : adrdata}
    });
}
//设置为默认收货地址
function setDefault(id){
	setAddress(id,RSapi.base+RSapi.AdrDft);
}
//删除收货地址
function setDelete(id){
	setAddress(id,RSapi.base+RSapi.AdrDel);
}
//设置默认，删除操作
function setAddress(id,url){
	var useParam = {
    	rtk : RSapi.myrtk,
        mytoken : db_user.mytoken,
        id : id,
    };
    api.ajax({
        url: url,
        method: 'post',
        cache: false,
        timeout: 30,
        dataType: 'json',
        data: { values: useParam },
    }, function(ret, err){
        if(err){
            //alert(JSON.stringify(err));
            api.toast({msg: JSON.stringify(err)});
        }else {
            if (ret.status == 1) {
                //成功了
				api.toast({msg:ret.info});
				loadAdress();
            }else {
                //失败了
                api.toast({msg: ret.info});
                loadAdress();
            }
        }
    });
    return false;
}
//选择收货地址
function selectadr(id) {
	NowAdrInfo(id);
    api.sendEvent({
        name: 'selectadr',
        extra: {
            newadr: adrdata,
        }
    });
    api.closeWin();
}
//获取当前地址记录的信息
function NowAdrInfo(id){
	adrdata = {};
	var adrdataObj = $api.byId("adr_"+id);
	adrdata = {
		'adrid'	  : id,
		'linkman' : adrdataObj.dataset.linkman,
		'contact' : adrdataObj.dataset.contact,
		'address' : adrdataObj.dataset.address,
		'doorplate' : adrdataObj.dataset.doorplate,
		'lng' : adrdataObj.dataset.lng,
		'lat' : adrdataObj.dataset.lat,
	};
}
</script>
</html>
